<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>人员权限管理</title>
    <script src="/jquery/jquery-3.2.1.min.js"></script>
    <script src="/layui/layui.js"></script>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <style>
        body{
            background-color: #EFEFEF;
        }
        .layui-card{
            margin-left: 7%;
        }

        .marTop{
            margin-top: 4%;
        }
        .right{
            position: absolute;
            bottom: 6%;
            right: 2%;
        }
    </style>
</head>
<body>
    <form class="layui-form" lay-filter="formTest">
        <div class="layui-row marTop">
            <div class="layui-col-xs11 layui-col-sm11 layui-col-md12">
                <div class="layui-form-item">
                    <label class="layui-form-label">用户名</label>
                    <div class="layui-input-block">
                        <input type="text" name="userName" disabled="disabled" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-row">
            <div class="layui-col-xs11 layui-col-sm11 layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">拥有权限</div>
                    <div class="layui-card-body">
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <input type="checkbox" lay-filter="filter" value="1" name="1" title="管理">
                                <input type="checkbox" lay-filter="filter" value="2" name="2" title="教师">
                                <input type="checkbox" lay-filter="filter" value="3" name="3" title="运营">
                                <input type="checkbox" lay-filter="filter" value="4" name="4" title="人事">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </form>

    <div class="layui-row marTop">
        <div class="layui-col-xs11 layui-col-sm11 layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">用户描述</div>
                <div class="layui-card-body">
                    用户描述
                </div>
            </div>
        </div>
    </div>
    <div class="right">
        <a class="layui-btn layui-btn-sm layui-btn-normal" href="javascript:cancel();">
            关闭
        </a>
        <a class="layui-btn layui-btn-sm layui-btn-primary" href="javascript:;cancel()">
            取消
        </a>
    </div>
</body>
    <script>
        var $;
        var element;
        var form;
        var table;
        var laydate;
        var status;
        var layer;
        var id = parent.getParentId();
        layui.use(['jquery','element','form','table','laydate','layer'],function () {
            $ = layui.$;
            element = layui.element;
            form = layui.form;
            table = layui.table;
            laydate = layui.laydate;
            layer = layui.layer;

            form.on('checkbox(filter)', function(data){
                if(data.elem.checked){
                    $.ajax({
                        url:'/Department/addJurisdiction',
                        dataType:'json',
                        data:{"userId":id,"deptId":data.value},
                        success:function (data) {
                            if(data.data){
                                layer.msg("已添加改权限");
                            }
                        }
                    });
                }else{
                    $.ajax({
                        url:'/Department/deleteJurisdiction',
                        dataType:'json',
                        data:{"userId":id,"deptId":data.value},
                        success:function (data) {
                            layer.msg("已去除该权限");
                        }
                    });
                }
            });

        });



        $.ajax({
            url:'/Department/getPermission',
            dataType:'json',
            data:{"id":id},
            success:function (data) {
                 data = data.data;
                 $.each(data, function(index,item){
                    $("input[name = "+item+"]").prop("checked",true);
                 });
                layui.form.render();
            }
        })
        var name = parent.account;
        $('input[name = userName]').val(name);
        function cancel() {
            var layer = parent.layer;
            layer.close(layer.index);
        }


    </script>
</html>